--
-- Author: yawei.zhu
-- Date: 2018-09-03 11:53:08
--
-- DungeonDropView
--

local DungeonDropItemRender = import(".DungeonDropItemRender")

local fileName = string.getModeName(...)
local ClassRef = class(fileName, app.mvc.ViewBase)

ClassRef.VIEW_ROOT_RES = Res.DungeonDropScene

function ClassRef:init()
	self._ui.Button_quxiao:addClickEventListener(function()
		
		self:hide(function()
			executeFunc(self._onCloseView)
		end)
		-- 是否显示宝箱
		if DungeonManager:isLuckBox() then
            app:sendMsg("BoxController", "openView",{boxType = Enums.BoxType.dungeon, dungeonID = DungeonManager:getDungeonSubId()})
        end
        -- 显示通关奖励
        DungeonManager:showPassDungeonAward()
	end)

	self._ui["Panel/Panel_n/tips_2"]:setString(L("NoLoot")) -- 再次击杀将不会获得奖励
	self._ui["bg"]:setTouchEnabled(true)
	self._ui.ListView:setVisible(false)
	self._ui.Panel_n:setVisible(false)
end

function ClassRef:setDrops(loots, rewardLimit, extra)
	if loots == nil or #loots <= 0 then
		self._ui.Panel_n:setVisible(true)

		local str = ""
		local tp = rewardLimit.type
		if tp == "daily" then
			str = string.format( L("DropLimit"), L("Today"), rewardLimit.limit)
		elseif tp == "weekly" then
			str = string.format( L("DropLimit"), L("ThisWeek"), rewardLimit.limit)
		elseif tp == "lv" then
			str = L("LowGradeDungeon")
		end
		self._ui.tips_1:setString(str)

		return
	end

	local listView = self._ui.ListView
	listView:setVisible(true)
	listView:removeAllChildren()
	for i = 1, #loots do
		local render = DungeonDropItemRender.create()
		render:setData({i, loots[i]}) 
		if extra and loots[i].type == Enums.PropType.eventPoint then
			render:setExtra(extra)
		end
		listView:pushBackCustomItem(render)
	end
	listView:refreshView()
end

return ClassRef
